package com.fywsy.fyweb.strategy;

import com.fywsy.fyweb.entity.SendItem;
import com.fywsy.fyweb.utils.RestTemplateUtil;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

/**
 * 游戏后台实现类
 * 注解gameId对应数据库游戏id
 * 注解GongnengMethod对应数据库功能id
 */
@Component
@GameId(84)
public class JiwushuangGameStrategy extends BaseGameStrategy {

    public static final String URL = "http://114.66.45.29:30281/htss/gm/query.php";

    /**
     * action=sendmoney&qid=1&uid=m66666&pswd=diyao88&chargetype=1010&chargenum=1
     * @param item
     * @return
     */
    @GongnengMethod(8401)
    public String pay(SendItem item) {
        MultiValueMap<String,String> params = new LinkedMultiValueMap<>();
        params.add("pswd", "diyao88");
        params.add("action", "sendmoney");
        params.add("qid", "1");

        params.add("uid", item.uid);
        params.add("chargenum", item.number);
        params.add("chargetype", item.itemId);

        return RestTemplateUtil.sendPostFormAndGetJsonKey(URL, params,"message");
    }

    /**
     * action=senditem&qid=1&uid=m66666&pswd=diyao88&itemid=2&itemnum=12
     * @param item
     * @return
     */
    @GongnengMethod(8402)
    public String mail(SendItem item) {
        MultiValueMap<String,String> params = new LinkedMultiValueMap<>();
        params.add("pswd", "diyao88");
        params.add("action", "senditem");
        params.add("qid", "1");

        params.add("uid", item.uid);
        params.add("itemnum", item.number);
        params.add("itemid", item.itemId);

        return RestTemplateUtil.sendPostFormAndGetJsonKey(URL, params,"message");
    }



    @GongnengMethod(9)
    public String clear(SendItem item) {
        System.out.println("清除成功");
        return "清除成功";
    }

    public static void main(String[] args) {
        SendItem item = new SendItem();
        item.uid = "m66666";
        item.number = "121";
        item.itemId = "3";
        System.out.println(new JiwushuangGameStrategy().mail(item));
    }
}

